from dash import Dash, html
from dash.dependencies import Input, Output
from dash import Dash, dcc, html,callback
from pages.backgroud.bg import backgroud
from pages.garden.item import Videos
from pages.garden.comment import Comments
from pages.datapannel.main import dataPannel
from pages.chat.dingyuanying import Chat
import json
from pages.garden.comment import Comment

app = Dash(__name__,suppress_callback_exceptions=True,title="《天道》")
app.interpolate_index(
    title="天道", 
    favicon="assets/favicon.ico",
)
app.layout = html.Div(
    [ dcc.Location(id="url", refresh=False), html.Div(id="page-content"),]
)



@app.callback(
    Output("page-content", "children"),
    [Input("url", "pathname")],
)
def display_page(pathname):
    if pathname.endswith("/background"):
        return backgroud()
    elif pathname.endswith("/datapannel"):
        return dataPannel()
    elif pathname.endswith("/creation"):
        return Videos()
    elif pathname.endswith("/garden"):
        return Comments()
    else:
        return Chat()




if __name__ == '__main__':
    ## 采用命令行参数设置端口号
    import sys
    import argparse
    import os
    parser = argparse.ArgumentParser(description='Run the app')
    parser.add_argument('--port', type=int, default=8010, help='port to run the app on')
    parser.add_argument('--debug',action=argparse.BooleanOptionalAction, help='enable debug mode')
    parser.add_argument('--deploy',action=argparse.BooleanOptionalAction, help='enable deploy mode')
    args = parser.parse_args()
    if args.deploy:
        from waitress import serve
        serve(app.server,host=os.getenv("HOST", "0.0.0.0"),port=args.port)
    else:
        app.run_server(debug=args.debug,host=os.getenv("HOST", "0.0.0.0"),port=args.port)